﻿using System;
using System.Linq;
using Thuoc24h.Business;
using Thuoc24h.Common;

namespace Thuoc24h.AdminCP.Pages
{
    public partial class CustomerDetail : BasePage.BasePages
    {
        private int _id;
        protected void Page_Load(object sender, EventArgs e)
        {
            _id = Request.QueryString["ID"].ToInt32Return0();
           if (!Page.IsPostBack)
           {
               var customer = ReviewRepository.GetCustomerById(_id);
               if (customer != null)
               {
                   ltrName.Text = customer.Name;
                   ltrAccount.Text = customer.UserName;
                   ltrPhone.Text = customer.Phone;
                   ltrEmail.Text = customer.Email;
                   ltrCreatedDate.Text = customer.CreatedDate.ToString();
                   ltrLastLoginDate.Text = customer.LastLoginDate.ToString();
                   ltrAddress.Text = customer.Address;
                   ltrStatus.Text = customer.Status == 1 ? "Đã kích hoạt" : "Chưa kích hoạt";
                   cbStatus.Checked = customer.Status == 1;
               }
           }
        }

        protected void cbStatus_OnCheckedChanged(object sender, EventArgs e)
        {
            var customer = context.Customers.SingleOrDefault(item => item.Id == _id);
            if (customer != null)
            {
                customer.Status = cbStatus.Checked ? 1 : 0;
            }
            if (context.SaveChanges() > 0)
            {
               
                    ltrStatus.Text = customer.Status == 1 ? "Đã kích hoạt" : "Chưa kích hoạt";
               
             
            }
        }
    }
}